package com.atguigu.service.service_msm.service.impl;

import com.atguigu.commonutils.jwt.RandomUtil;
import com.atguigu.service.service_msm.service.EmailService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: Administrator
 * @date: 2021-04-12 17:30
 */
@Service("emailService")
public class EmailServiceImpl implements EmailService {


    @Resource
    JavaMailSender mailSender;

    @Override
    public Map<String,Object> sendEmailMesssage(String code, String emailTo) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //邮件标题
        mailMessage.setSubject("测试邮件验证码");
        // TODO塞入验证，这里可以重新搞个类专门写模板
        mailMessage.setText(code);
        //发送人(必须和配置文件中的username相同)固定的
        mailMessage.setFrom("13918471632@163.com");
        //收件人
        mailMessage.setTo(emailTo);
        //发送..
        mailSender.send(mailMessage);
        //放入redis的验证码和邮箱
        Map<String,Object> param=new HashMap<>();
        param.put("code",code);
        param.put("emailTo",emailTo);
        return param;
    }
}
